﻿using System.DirectoryServices;

namespace Hx.ADSyncPlatform.ActiveDirectory.Api
{
    public class ApiBase
    {

        private ActiveDirectoryClient activeDirectoryClient { get; set; }


        public ApiBase(ActiveDirectoryClient activeDirectoryClient)
        {
            this.activeDirectoryClient = activeDirectoryClient;
        }

        /// <summary>
        /// 获得DirectoryEntry对象实例,以当前用户登陆AD
        /// </summary>
        /// <returns></returns>
        protected DirectoryEntry GetDirectoryObject()
        {
            DirectoryEntry entry = new DirectoryEntry(this.activeDirectoryClient.ADPath, activeDirectoryClient.Account, activeDirectoryClient.Password, AuthenticationTypes.Secure);
            return entry;
        }

        protected DirectoryEntry GetTargetLDAP(string targetLDAP)
        {

            DirectoryEntry entry = new DirectoryEntry(this.activeDirectoryClient.ADPath + "/" + targetLDAP, activeDirectoryClient.Account, activeDirectoryClient.Password, AuthenticationTypes.Secure);
            return entry;
        }
    }
}
